package App.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * 在线接口文档
 * @author zhouxt
 */
@Configuration
@EnableSwagger2
public class Swagger2 {


    @Bean
    public Docket createAllRestApi() {

        ParameterBuilder ticketPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        ticketPar.name("Authorization").description("请求token")
                .modelRef(new ModelRef("string")).parameterType("header")
                //header中的ticket参数非必填，传空也可以
                .required(false).build();
        pars.add(ticketPar.build());

//        ticketPar.name("phoneType").description("手机端版本（ios,app）")
//                .modelRef(new ModelRef("string")).parameterType("header")
//                //header中的ticket参数非必填，传空也可以
//                .required(false).build();
//        pars.add(ticketPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("法力接口")
                .globalOperationParameters(pars)
                .apiInfo(new ApiInfoBuilder()
                        .title("法力接口")
                        .version("1.0")
                        .build()
                )
                .select()
                .apis(RequestHandlerSelectors.basePackage("App"))
                .paths(PathSelectors.any())
                .build();
    }






}
